package com.hzhr.iot.collect.convertor;

import com.hzhr.iot.collect.convertor.custom.*;
import com.hzhr.iot.core.util.HzhrTypeUtil;
import com.hzhr.iot.core.util.HzhrJsonUtil;
import java.util.Map;
import com.hzhr.iot.collect.model.collectLog.CollectLogModel;
import com.hzhr.iot.collect.model.collectLog.CollectLogPostModel;
import com.hzhr.iot.collect.entity.CollectLogEntity;
import com.hzhr.iot.collect.entity.ext.CollectLogEntityExt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.hzhr.iot.collect.model.collectLog.CollectLogModel;
import com.hzhr.iot.collect.model.collectLog.CollectLogGetModel;
import com.hzhr.iot.collect.model.collectLog.CollectLogPostModel;
import com.hzhr.iot.collect.queryModel.custom.CollectLogCustomQueryModel;

@Component
public class CollectLogConvertor {
    @Autowired
    CachedCommandCustomConvertor cachedCommandCustomConvertor;
    @Autowired
    CommandCountCustomConvertor commandCountCustomConvertor;

    public CollectLogEntity collectLogModel2entity(CollectLogModel in) {
        //未转换字段: 
        if (in == null) return null;
        CollectLogEntity result = new CollectLogEntity();

        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setProtocalId(HzhrTypeUtil.integer2integer(in.getProtocalId()));
        result.setFunctionCode(HzhrTypeUtil.string2string(in.getFunctionCode()));
        result.setMessageId(HzhrTypeUtil.string2string(in.getMessageId()));
        result.setCollectDeviceId(HzhrTypeUtil.integer2integer(in.getCollectDeviceId()));
        result.setIotDeviceId(HzhrTypeUtil.integer2integer(in.getIotDeviceId()));
        result.setIotDeviceCode(HzhrTypeUtil.string2string(in.getIotDeviceCode()));
        result.setIotDeviceImei(HzhrTypeUtil.string2string(in.getIotDeviceImei()));
        result.setStarter(HzhrTypeUtil.integer2integer(in.getStarter()));
        result.setType(HzhrTypeUtil.integer2integer(in.getType()));
        result.setStartTime(HzhrTypeUtil.long2date(in.getStartTime()));
        result.setMessage(HzhrTypeUtil.string2string(in.getMessage()));
        result.setMessageObj(HzhrTypeUtil.string2string(in.getMessageObj()));
        result.setInfo(HzhrTypeUtil.string2string(in.getInfo()));
        return result;
    }
    public CollectLogEntity collectLogModel2entity(CollectLogModel in, CollectLogEntity ori) {
        //未转换字段: 
        if (in == null) return null;
        CollectLogEntity result = ori;

        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setProtocalId(HzhrTypeUtil.integer2integer(in.getProtocalId()));
        result.setFunctionCode(HzhrTypeUtil.string2string(in.getFunctionCode()));
        result.setMessageId(HzhrTypeUtil.string2string(in.getMessageId()));
        result.setCollectDeviceId(HzhrTypeUtil.integer2integer(in.getCollectDeviceId()));
        result.setIotDeviceId(HzhrTypeUtil.integer2integer(in.getIotDeviceId()));
        result.setIotDeviceCode(HzhrTypeUtil.string2string(in.getIotDeviceCode()));
        result.setIotDeviceImei(HzhrTypeUtil.string2string(in.getIotDeviceImei()));
        result.setStarter(HzhrTypeUtil.integer2integer(in.getStarter()));
        result.setType(HzhrTypeUtil.integer2integer(in.getType()));
        result.setStartTime(HzhrTypeUtil.long2date(in.getStartTime()));
        result.setMessage(HzhrTypeUtil.string2string(in.getMessage()));
        result.setMessageObj(HzhrTypeUtil.string2string(in.getMessageObj()));
        result.setInfo(HzhrTypeUtil.string2string(in.getInfo()));
        return result;
    }
    public List<CollectLogEntity> collectLogModelList2entityList(List<CollectLogModel> in) {
        if (in == null) return null;
        List<CollectLogEntity> result = new ArrayList<>();
        for (CollectLogModel item : in) {
            result.add(collectLogModel2entity(item));
        }
        return result;
    }
    public CollectLogModel entity2collectLogModel(CollectLogEntity in) {
        //未转换字段: functionName 
        if (in == null) return null;
        CollectLogModel result = new CollectLogModel();

        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setProtocalId(HzhrTypeUtil.integer2integer(in.getProtocalId()));
        result.setFunctionCode(HzhrTypeUtil.string2string(in.getFunctionCode()));
        result.setMessageId(HzhrTypeUtil.string2string(in.getMessageId()));
        result.setCollectDeviceId(HzhrTypeUtil.integer2integer(in.getCollectDeviceId()));
        result.setIotDeviceId(HzhrTypeUtil.integer2integer(in.getIotDeviceId()));
        result.setIotDeviceCode(HzhrTypeUtil.string2string(in.getIotDeviceCode()));
        result.setIotDeviceImei(HzhrTypeUtil.string2string(in.getIotDeviceImei()));
        result.setStarter(HzhrTypeUtil.integer2integer(in.getStarter()));
        result.setType(HzhrTypeUtil.integer2integer(in.getType()));
        result.setStartTime(HzhrTypeUtil.date2long(in.getStartTime()));
        result.setMessage(HzhrTypeUtil.string2string(in.getMessage()));
        result.setMessageObj(HzhrTypeUtil.string2string(in.getMessageObj()));
        result.setInfo(HzhrTypeUtil.string2string(in.getInfo()));
        return result;
    }
    public List<CollectLogModel> entityList2collectLogModelList(List<CollectLogEntity> in) {
        if (in == null) return null;
        List<CollectLogModel> result = new ArrayList<>();
        for (CollectLogEntity item : in) {
            result.add(entity2collectLogModel(item));
        }
        return result;
    }
    public CollectLogModel ext2collectLogModel(CollectLogEntityExt in) {
        //未转换字段: functionName 
        if (in == null) return null;
        CollectLogModel result = new CollectLogModel();

        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setProtocalId(HzhrTypeUtil.integer2integer(in.getProtocalId()));
        result.setFunctionCode(HzhrTypeUtil.string2string(in.getFunctionCode()));
        result.setMessageId(HzhrTypeUtil.string2string(in.getMessageId()));
        result.setCollectDeviceId(HzhrTypeUtil.integer2integer(in.getCollectDeviceId()));
        result.setIotDeviceId(HzhrTypeUtil.integer2integer(in.getIotDeviceId()));
        result.setIotDeviceCode(HzhrTypeUtil.string2string(in.getIotDeviceCode()));
        result.setIotDeviceImei(HzhrTypeUtil.string2string(in.getIotDeviceImei()));
        result.setStarter(HzhrTypeUtil.integer2integer(in.getStarter()));
        result.setType(HzhrTypeUtil.integer2integer(in.getType()));
        result.setStartTime(HzhrTypeUtil.date2long(in.getStartTime()));
        result.setMessage(HzhrTypeUtil.string2string(in.getMessage()));
        result.setMessageObj(HzhrTypeUtil.string2string(in.getMessageObj()));
        result.setInfo(HzhrTypeUtil.string2string(in.getInfo()));
        return result;
    }
    public List<CollectLogModel> extList2collectLogModelList(List<CollectLogEntityExt> in) {
        if (in == null) return null;
        List<CollectLogModel> result = new ArrayList<>();
        for (CollectLogEntityExt item : in) {
            result.add(ext2collectLogModel(item));
        }
        return result;
    }
    public CollectLogGetModel extList2collectLogGetModel(List<CollectLogEntityExt> extList, Integer total, Integer changeCount, Map<String, Object> query) {
        List<CollectLogModel> modelList = extList2collectLogModelList(extList);
        if (modelList == null) {
            CollectLogGetModel result = new CollectLogGetModel();
            result.setTotal(total);
            result.setChangeCount(changeCount);
            return result;
        }

         String _show = HzhrTypeUtil.object2string(query.get("_show"));
         Boolean _show_info = query.get("_show_info") != null ? Boolean.parseBoolean(query.get("_show_info").toString()) : false;

        if (!_show_info) {
            for (CollectLogModel model : modelList) {
                model.setProtocalId(null);
                model.setFunctionCode(null);
                model.setFunctionName(null);
                model.setMessageId(null);
                model.setCollectDeviceId(null);
                model.setIotDeviceId(null);
                model.setIotDeviceCode(null);
                model.setIotDeviceImei(null);
                model.setStarter(null);
                model.setType(null);
                model.setStartTime(null);
                model.setMessage(null);
                model.setMessageObj(null);
                model.setInfo(null);
            }
        }

        CollectLogGetModel result = new CollectLogGetModel();
        if ("one".equals(_show)) {
            if (modelList.size() > 0) {
                result.setModel(modelList.get(0));
            }
         }
        if ("list".equals(_show)) {
            result.setModelList(modelList);
        }
        result.setTotal(total);
        result.setChangeCount(changeCount);
        return result;
    }
    public CollectLogGetModel entity2collectLogGetModel(CollectLogEntity entity, Integer total, Integer changeCount, Map<String, Object> query) {
        List<CollectLogEntityExt> extList = new ArrayList<>();
        if (entity == null) return extList2collectLogGetModel(extList, total, changeCount, query);
        extList.add(HzhrJsonUtil.convertObjectType(entity, CollectLogEntityExt.class));
        return extList2collectLogGetModel(extList, total, changeCount, query);
     }
    public CollectLogEntity collectLogPostModel2entity(CollectLogPostModel in) {
        //未转换字段: id 
        if (in == null) return null;
        CollectLogEntity result = new CollectLogEntity();

        result.setProtocalId(HzhrTypeUtil.integer2integer(in.getProtocalId()));
        result.setFunctionCode(HzhrTypeUtil.string2string(in.getFunctionCode()));
        result.setMessageId(HzhrTypeUtil.string2string(in.getMessageId()));
        result.setCollectDeviceId(HzhrTypeUtil.integer2integer(in.getCollectDeviceId()));
        result.setIotDeviceId(HzhrTypeUtil.integer2integer(in.getIotDeviceId()));
        result.setIotDeviceCode(HzhrTypeUtil.string2string(in.getIotDeviceCode()));
        result.setIotDeviceImei(HzhrTypeUtil.string2string(in.getIotDeviceImei()));
        result.setStarter(HzhrTypeUtil.integer2integer(in.getStarter()));
        result.setType(HzhrTypeUtil.integer2integer(in.getType()));
        result.setStartTime(HzhrTypeUtil.long2date(in.getStartTime()));
        result.setMessage(HzhrTypeUtil.string2string(in.getMessage()));
        result.setMessageObj(HzhrTypeUtil.string2string(in.getMessageObj()));
        result.setInfo(HzhrTypeUtil.string2string(in.getInfo()));
        return result;
    }
    public CollectLogEntity collectLogPostModel2entity(CollectLogPostModel in, CollectLogEntity ori) {
        //未转换字段: id 
        if (in == null) return null;
        CollectLogEntity result = ori;

        result.setProtocalId(HzhrTypeUtil.integer2integer(in.getProtocalId()));
        result.setFunctionCode(HzhrTypeUtil.string2string(in.getFunctionCode()));
        result.setMessageId(HzhrTypeUtil.string2string(in.getMessageId()));
        result.setCollectDeviceId(HzhrTypeUtil.integer2integer(in.getCollectDeviceId()));
        result.setIotDeviceId(HzhrTypeUtil.integer2integer(in.getIotDeviceId()));
        result.setIotDeviceCode(HzhrTypeUtil.string2string(in.getIotDeviceCode()));
        result.setIotDeviceImei(HzhrTypeUtil.string2string(in.getIotDeviceImei()));
        result.setStarter(HzhrTypeUtil.integer2integer(in.getStarter()));
        result.setType(HzhrTypeUtil.integer2integer(in.getType()));
        result.setStartTime(HzhrTypeUtil.long2date(in.getStartTime()));
        result.setMessage(HzhrTypeUtil.string2string(in.getMessage()));
        result.setMessageObj(HzhrTypeUtil.string2string(in.getMessageObj()));
        result.setInfo(HzhrTypeUtil.string2string(in.getInfo()));
        return result;
    }
    public List<CollectLogEntity> collectLogPostModelList2entityList(List<CollectLogPostModel> in) {
        if (in == null) return null;
        List<CollectLogEntity> result = new ArrayList<>();
        for (CollectLogPostModel item : in) {
            result.add(collectLogPostModel2entity(item));
        }
        return result;
    }
    public CollectLogPostModel entity2collectLogPostModel(CollectLogEntity in) {
        //未转换字段: 
        if (in == null) return null;
        CollectLogPostModel result = new CollectLogPostModel();

        result.setProtocalId(HzhrTypeUtil.integer2integer(in.getProtocalId()));
        result.setFunctionCode(HzhrTypeUtil.string2string(in.getFunctionCode()));
        result.setMessageId(HzhrTypeUtil.string2string(in.getMessageId()));
        result.setCollectDeviceId(HzhrTypeUtil.integer2integer(in.getCollectDeviceId()));
        result.setIotDeviceId(HzhrTypeUtil.integer2integer(in.getIotDeviceId()));
        result.setIotDeviceCode(HzhrTypeUtil.string2string(in.getIotDeviceCode()));
        result.setIotDeviceImei(HzhrTypeUtil.string2string(in.getIotDeviceImei()));
        result.setStarter(HzhrTypeUtil.integer2integer(in.getStarter()));
        result.setType(HzhrTypeUtil.integer2integer(in.getType()));
        result.setStartTime(HzhrTypeUtil.date2long(in.getStartTime()));
        result.setMessage(HzhrTypeUtil.string2string(in.getMessage()));
        result.setMessageObj(HzhrTypeUtil.string2string(in.getMessageObj()));
        result.setInfo(HzhrTypeUtil.string2string(in.getInfo()));
        return result;
    }
    public List<CollectLogPostModel> entityList2collectLogPostModelList(List<CollectLogEntity> in) {
        if (in == null) return null;
        List<CollectLogPostModel> result = new ArrayList<>();
        for (CollectLogEntity item : in) {
            result.add(entity2collectLogPostModel(item));
        }
        return result;
    }
    public CollectLogPostModel ext2collectLogPostModel(CollectLogEntityExt in) {
        //未转换字段: 
        if (in == null) return null;
        CollectLogPostModel result = new CollectLogPostModel();

        result.setProtocalId(HzhrTypeUtil.integer2integer(in.getProtocalId()));
        result.setFunctionCode(HzhrTypeUtil.string2string(in.getFunctionCode()));
        result.setMessageId(HzhrTypeUtil.string2string(in.getMessageId()));
        result.setCollectDeviceId(HzhrTypeUtil.integer2integer(in.getCollectDeviceId()));
        result.setIotDeviceId(HzhrTypeUtil.integer2integer(in.getIotDeviceId()));
        result.setIotDeviceCode(HzhrTypeUtil.string2string(in.getIotDeviceCode()));
        result.setIotDeviceImei(HzhrTypeUtil.string2string(in.getIotDeviceImei()));
        result.setStarter(HzhrTypeUtil.integer2integer(in.getStarter()));
        result.setType(HzhrTypeUtil.integer2integer(in.getType()));
        result.setStartTime(HzhrTypeUtil.date2long(in.getStartTime()));
        result.setMessage(HzhrTypeUtil.string2string(in.getMessage()));
        result.setMessageObj(HzhrTypeUtil.string2string(in.getMessageObj()));
        result.setInfo(HzhrTypeUtil.string2string(in.getInfo()));
        return result;
    }
    public List<CollectLogPostModel> extList2collectLogPostModelList(List<CollectLogEntityExt> in) {
        if (in == null) return null;
        List<CollectLogPostModel> result = new ArrayList<>();
        for (CollectLogEntityExt item : in) {
            result.add(ext2collectLogPostModel(item));
        }
        return result;
    }
    public CollectLogCustomQueryModel collectLogService_query2queryModel(Map<String, Object> query) {
        CollectLogCustomQueryModel queryModel = new CollectLogCustomQueryModel();

        Integer _equal_id = HzhrTypeUtil.object2integer(query.get("_equal_id"));
        if (_equal_id != null) {
            queryModel.setEqual_id(_equal_id);
         }

        Integer _equal_collectDeviceId = HzhrTypeUtil.object2integer(query.get("_equal_collectDeviceId"));
        if (_equal_collectDeviceId != null) {
            queryModel.setEqual_collectDeviceId(_equal_collectDeviceId);
         }

        Integer _equal_iotDeviceId = HzhrTypeUtil.object2integer(query.get("_equal_iotDeviceId"));
        if (_equal_iotDeviceId != null) {
            queryModel.setEqual_iotDeviceId(_equal_iotDeviceId);
         }

        String _equal_iotDeviceCode = HzhrTypeUtil.object2string(query.get("_equal_iotDeviceCode"));
        if (_equal_iotDeviceCode != null) {
            queryModel.setEqual_iotDeviceCode(_equal_iotDeviceCode);
         }

        String _like_iotDeviceCode = HzhrTypeUtil.object2string(query.get("_like_iotDeviceCode"));
        if (_like_iotDeviceCode != null) {
            queryModel.setLike_iotDeviceCode(_like_iotDeviceCode);
         }

        String _equal_functionCode = HzhrTypeUtil.object2string(query.get("_equal_functionCode"));
        if (_equal_functionCode != null) {
            queryModel.setEqual_functionCode(_equal_functionCode);
         }

        Integer _equal_type = HzhrTypeUtil.object2integer(query.get("_equal_type"));
        if (_equal_type != null) {
            queryModel.setEqual_type(_equal_type);
         }

        Integer _equal_starter = HzhrTypeUtil.object2integer(query.get("_equal_starter"));
        if (_equal_starter != null) {
            queryModel.setEqual_starter(_equal_starter);
         }

        Date _greaterthanorequal_startTime = HzhrTypeUtil.object2date(query.get("_greaterthanorequal_startTime"));
        if (_greaterthanorequal_startTime != null) {
            queryModel.setGreaterthanorequal_startTime(_greaterthanorequal_startTime);
         }

        Date _lessthan_startTime = HzhrTypeUtil.object2date(query.get("_lessthan_startTime"));
        if (_lessthan_startTime != null) {
            queryModel.setLessthan_startTime(_lessthan_startTime);
         }

        Boolean _show_info = HzhrTypeUtil.object2boolean(query.get("_show_info"));
        if (_show_info != null && _show_info) {
            queryModel.setShow(true);
            queryModel.setShow(true);
            queryModel.setShow(true);
            queryModel.setShow(true);
            queryModel.setShow(true);
            queryModel.setShow(true);
            queryModel.setShow(true);
            queryModel.setShow(true);
            queryModel.setShow(true);
            queryModel.setShow(true);
            queryModel.setShow(true);
            queryModel.setShow(true);
            queryModel.setShow(true);
        }

        Integer page = HzhrTypeUtil.object2integer(query.get("_page"));
        Integer count = HzhrTypeUtil.object2integer(query.get("_count"));
        queryModel.setPage(page, count);

        return queryModel;
    }

}

